/**
 *  @file gameEngine.h
 *
 *  @date 24-nov-2009
 *  @author Ives van der Flaas
 */

#ifndef GAMEENGINE_H_
#define GAMEENGINE_H_

#include <vector>
#include <map>
#include <tr1/memory>
#include "sprite.h"
#include "objectFactory.h"
#include "friendlyShip.h"
#include "timer.h"
#include "levelInfo.h"
#include "representation.h"
#include "levelTitle.h"
#include "collisionDetector.h"
#include "scoreKeeper.h"

namespace si
{
/**
 * Will be returned by newFrame. NONE if nothing special happened, LOSTGAME if we lost the game and
 * WONGAME if we won the game.
 */
enum FrameResult { NONE, LOSTGAME, WONGAME };

/**
 * The class that will represent The Actual Game
 * (Yes, The Actual Game! I know it's hard to believe
 * but it may be true...
 */
class GameEngine
{
public:
	GameEngine(std::tr1::shared_ptr<ObjectFactory> theObjectFactory);
	void reset();
	virtual ~GameEngine();

	virtual FrameResult newFrame(double timePassed);
	void makeEnemies();
	void newLevel();

	int getScore() const { return fUserShip->getScore(); }

protected:
	/**
	 * A list that will store all objects that will
	 * be updated and drawn. This includes the user's ship.
	 */
	std::vector<std::tr1::shared_ptr<Ship> > fShips;

	std::tr1::shared_ptr<FriendlyShip> fUserShip;
	std::tr1::shared_ptr<Representation> fBackground;

private:
	void loadLevels();
	void loadShips();
	LevelInfo fLevelInfo;
	int fCurrentLevel;
	std::tr1::shared_ptr<Timer> fTimer;
	std::tr1::shared_ptr<Timer> fLevelTimer;
	std::tr1::shared_ptr<LevelTitle> fLevelTitle;

	std::tr1::shared_ptr<ObjectFactory> fObjectFactory;

	std::map<std::string,ShipDescr> fShipDb;

	CollisionDetector collisionDetector;

};

}

#endif /* GAMEENGINE_H_ */
